package com.lepu.app.fun.mother_circle.adapter;

import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.eyzhs.app.R;
import com.lepu.app.fun.mother_circle.MotherTopicActivity;
import com.lepu.app.fun.mother_circle.bean.BeanMotherTopic;
import com.lepu.app.fun.my.PubContentDetailActivity;

public class AdapterMotherTopicHead extends BaseAdapter {

	private LayoutInflater mLayoutInflater = null;
	private Context mContext = null;
	private ArrayList<BeanMotherTopic> mArrayList = null;

	public AdapterMotherTopicHead(Context context,ArrayList<BeanMotherTopic> arrayList) {
		mContext = context;
		mLayoutInflater = LayoutInflater.from(context);
		mArrayList = arrayList;
	}

	@Override
	public int getCount() {
		int size = 0;
		if (mArrayList != null && mArrayList.size() > 0) {
			size = mArrayList.size();
		}
		return size;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		final ViewHolder holder;

		if (convertView == null) {
			convertView = mLayoutInflater.inflate(R.layout.mother_topic_head_item, null);

			holder = new ViewHolder();

			LinearLayout itemLayout = (LinearLayout) convertView.findViewById(R.id.itemContentLayout);
			TextView itemTextView = (TextView) convertView.findViewById(R.id.topic_head_item_text);

			TextView topic_item_comment = (TextView) convertView.findViewById(R.id.topic_item_comment);
			TextView topic_item_look = (TextView) convertView.findViewById(R.id.topic_item_look);

			holder.itemLayout = itemLayout;
			holder.itemTextView = itemTextView;
			holder.topic_item_comment = topic_item_comment;
			holder.topic_item_look = topic_item_look;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		final BeanMotherTopic item = mArrayList.get(position);
		holder.itemTextView.setText(item.topicTitle);
		holder.topic_item_comment.setText(item.topicCommentCount);
		holder.topic_item_look.setText(item.topicLookCount);

		holder.itemLayout.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext,PubContentDetailActivity.class);
				intent.putExtra("tag", 1);
				intent.putExtra("TopicId", item.topicID);
				intent.putExtra("nameType", 1);
				((MotherTopicActivity)mContext).startActivity(intent, true);
			}
		});

		return convertView;
	}

	private static class ViewHolder {
		LinearLayout itemLayout;
		TextView itemTextView;
		TextView topic_item_comment;
		TextView topic_item_look;

	}
}
